package com.lh.bootswagger.service.impl;

import com.lh.bootswagger.entity.Student;
import com.lh.bootswagger.repository.StudentRepository;
import com.lh.bootswagger.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author lh
 * @Description: student增删改查
 * @date 2021/3/24 13:40
 */
@Service
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentRepository studentRepository;

	@Override
	public void saveOne(Student stu) {
		studentRepository.save(stu);
	}

	@Override
	public void delStudentBySid(String sId) {
		studentRepository.deleteById(sId);
	}

	@Override
	public void updateStudent(Student stu) {
		studentRepository.save(stu);
	}

	@Override
	public List<Student> findAllStudent() {
		return studentRepository.findAll();
	}

	@Override
	public Student findStudentBySid(String sId) {
		Optional<Student> optStu = studentRepository.findById(sId);
		if (optStu.isPresent()) {
			return optStu.get();
		}

		return null;
	}
}
